home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / listings / v_12_08 / weber / sclfxln.c < prev   
Encoding:
Text File  |  1994-06-11  |  2.6 KB  |  71 lines

  1. /************************************************
  2.  * function: int scale_fax_line(unsigned char *dest, unsigned char *src)
  3.  ************************************************/
  4. int scale_fax_line(unsigned char *dest, unsigned char *src)
  5.     {
  6.     int y_repeat,x_repeat,i,bit;
  7.     unsigned int accum;
  8.     unsigned char byte;
  9.     unsigned char *start;
  10.     ROTATOR rotator;
  11.  
  12.     /* get line repeat value and rotate to next */
  13.     y_repeat = y_base + (y_rotator & 0x01);
  14.     _ror(y_rotator);
  15.     /* if anything to do */
  16.     if (y_repeat)
  17.         {
  18.         rotator = x_rotator;
  19.         for (i=source_width, accum=1, start=dest ; i > 0 ; i--, src++)
  20.             {       /* each byte in the source line */
  21.             if (*src)
  22.                 {   /* if it has black bits */
  23.                 for (bit=8, byte=*src ; bit > 0 ; bit--)
  24.                     {   /* for each bit in the byte */
  25.                     x_repeat = x_base + (rotator & 1);
  26.                     _ror(rotator);      /* get repeat count and rotate */
  27.                     while (x_repeat--)
  28.                         {               /* for each repeat */
  29.                         accum <<= 1;    /* copy bit into accumulator */
  30.                         accum += ((byte & 0x80) != 0);
  31.                         if (accum & 0x100)
  32.                             {           /* output a byte and reset sentinel */
  33.                             *dest++ = (unsigned char) accum;
  34.                             accum = 1;
  35.                             }
  36.                         }
  37.                     byte <<= 1;
  38.                     }
  39.                 }
  40.             else
  41.                 {   /* no black bits, just spin it out. */
  42.                 /* how many repeats? */
  43.                 x_repeat = bit_repeat_count + ((rotator & 0xff) > bit_repeat_pattern);
  44.                 /* rotate by 8 */
  45.                 rotator = (rotator << (PRECISION-8)) | (rotator >> 8);
  46.                 /* do it */
  47.                 while (x_repeat--)
  48.                     {
  49.                     accum <<= 1;
  50.                     if (accum & 0x100)
  51.                         {
  52.                         *dest++ = (unsigned char) accum;
  53.                         accum = 1;
  54.                         }
  55.                     }
  56.                 }
  57.             }
  58.         if (accum > 1)
  59.             {                       /* handle fragment */
  60.             while ((accum & 0x100) == 0)
  61.                 accum <<= 1;
  62.             *dest++ = (unsigned char) accum;
  63.             }
  64.         while (dest < start + FAX_WIDTH)
  65.             {                       /* white out tail */
  66.             *dest++ = 0;
  67.             }
  68.         }
  69.     return y_repeat;
  70.     }
  71.